library MuzzleBrakeSuppressor initializer init requires LegacySystem

	globals
		private sound MZBSound = null
	endglobals
	
	private function MuzzleBrakeSuppressorConditions takes nothing returns boolean
		return GetLearnedSkill()=='A04S'
	endfunction
	
	private  function MuzzleBrakeSuppressor takes nothing returns nothing
		local unit u = GetTriggerUnit()
		local player p = GetOwningPlayer(u)
		local sound s 

		if MZBSound == null then
			set MZBSound = CreateSound("war3mapImported\\SuppressorOn2.mp3", false, false, false, 10, 10, "DefaultEAXON")
			call SetSoundChannel(MZBSound,3)
		endif

		if GetLocalPlayer() == p then
			call StopSound(MZBSound, false, false)
			call StartSound(MZBSound)
		endif

		if GetPlayerTechCount(GetOwningPlayer(u),'R00O',true)==0 then
			call SetPlayerTechResearched(GetOwningPlayer(u),'R00O',1)
			call SetUnitAbilityLevel(u, 'A095', 2)
		else
			call IncUnitAbilityLevel(u,'A00J')
		endif
		if GetUnitAbilityLevel(u,'A04S')==5 and udg_Mode!=3 then
			call DisableTrigger(GetTriggeringTrigger())
		endif
		set u = null
		set p = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger()
		call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_HERO_SKILL )
		call TriggerAddCondition(t, Condition(function MuzzleBrakeSuppressorConditions))
		call TriggerAddAction( t, function MuzzleBrakeSuppressor )
	endfunction

endlibrary

